package zoujt.service;



/*
 * @auth zoujt
 * @date 2021/2/25
 * @Description
 */


import zoujt.dao.UserDao;
import zoujt.entitys.User;
import zoujt.untils.DateUtil;
import zoujt.untils.Md5Util;

import java.util.ArrayList;

public class UserService {
    private UserDao userDao = new UserDao();
    //查询所有
    public ArrayList<User> listAll() {
        ArrayList<User> list = userDao.listAll();
        return list;
    }
    //登录验证
    public ArrayList<User> checkNameAndPassword(String username,String password) {
        ArrayList<User> list = userDao.checkNameAndPassword(username, Md5Util.md5(password));
        return list;
    }


    //添加用户
    public void userAdd(User user) {
        user.setPassword(Md5Util.md5(user.getPassword()));
        String time = DateUtil.getTime();
        user.setCreateTime(time);
        userDao.userAdd(user);
    }

    //删除用户
    public void userDelete(Integer id){
        userDao.userDelete(id);
    }

    //修改用户
    public User updateById(Integer id){
        User user = userDao.updateById(id);
        return user;
    }
    public void userUpdate(User user){
        user.setPassword(Md5Util.md5(user.getPassword()));
        userDao.userUpdate(user);
    }

}